package com.myidis.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.myidis.entity.RightPermission;
import com.myidis.servlet.RightPermissionServlet;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;;

@Controller
@RequestMapping("/permission")
@Api(tags = "权限管理接口")
public class RightPermissionController {
	@Autowired
	private RightPermissionServlet rightPermissionServlet;
	
	@ResponseBody
	@RequestMapping("/list")
	@ApiOperation("获取所有权限的信息")
	public List<RightPermission> list() {
		return rightPermissionServlet.all();
	}
	
	@ResponseBody
	@RequestMapping("/entity")
	@ApiOperation("获取一个权限的信息")
	public RightPermission one(@RequestBody RightPermission rightPermission) {
		return rightPermissionServlet.getOne(rightPermission.getId());
	}
	
	@ResponseBody
	@RequestMapping("/add")
	@ApiOperation("添加一个权限")
	public int add(@RequestBody RightPermission rightPermission) {
		return rightPermissionServlet.insert(rightPermission);
	}
	
	@ResponseBody
	@RequestMapping("/addAll")
	@ApiOperation("添加一组权限")
	public int addAll(@RequestBody List<RightPermission> rightPermissions) {
		return rightPermissionServlet.insertAll(rightPermissions);
	}
	
	@ResponseBody
	@RequestMapping("/upd")
	@ApiOperation("修改一个权限")
	public int upd(@RequestBody RightPermission rightPermission) {
		return rightPermissionServlet.update(rightPermission);
	}

	@ResponseBody
	@RequestMapping("/del")
	@ApiOperation("删除一个权限")
	public int del(@RequestBody int id) {
		return rightPermissionServlet.delete(id);
	}
	
	@ResponseBody
	@RequestMapping("/delAll")
	@ApiOperation("删除一组权限")
	public int delAll(@RequestBody int[] ids) {
		return rightPermissionServlet.deleteAll(ids);
	}
}
